package com.xu.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.ArrayList;
import java.util.List;

public class EncryptUtil {

    public static List<String> encrypt(String pwd){
        ArrayList<String> strings = new ArrayList<>();
        String hashAlgorithmName = "MD5"; //加密方式
        int hashIterations = 2; //加密的次数
        String salt = new SecureRandomNumberGenerator().nextBytes().toHex();
        //加密
        SimpleHash simpleHash = new SimpleHash(hashAlgorithmName,pwd, salt, hashIterations);  //加盐
        String newPwd = simpleHash.toString();
        strings.add(newPwd);
        strings.add(salt);
        return strings;
    }

    public static String encrypt(String pwd,String salt){
        String hashAlgorithmName = "MD5"; //加密方式
        int hashIterations = 2; //加密的次数
        //加密
        SimpleHash simpleHash = new SimpleHash(hashAlgorithmName,pwd, salt, hashIterations);  //加盐
        return simpleHash.toString();
    }


}
